document.addEventListener('DOMContentLoaded', () => {
    document.addEventListener('keypress', (e) => {
        if (e.key === 'Enter') {
            authModule.register();
        }
    });
});

// 扩展 authModule，修改注册成功后的行为
const originalRegister = authModule.register;
authModule.register = function() {
    const username = document.getElementById('register-username').value;
    const password = document.getElementById('register-password').value;
    const confirmPassword = document.getElementById('register-password-confirm').value;

    if (!username || !password || !confirmPassword) {
        alert('请填写所有字段！');
        return;
    }

    if (password !== confirmPassword) {
        alert('两次输入的密码不一致！');
        return;
    }

    if (dataModule.addUser(username, password)) {
        alert('注册成功！即将跳转到登录页面');
        window.location.href = 'login.html';
    } else {
        alert('用户名已存在！');
    }
}; 